home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 265_01 / load.c < prev    next >
Text File  |  1990-02-13  |  3KB  |  117 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <ctype.h>
  4.  
  5. #define TESTING 0
  6. #define MAX_LINE 128
  7. #define DISP_WID 64
  8.  
  9. /*
  10.    customize these defines to make high-level functions
  11.    conform to the disk format
  12. */
  13.  
  14. #define DR_SEL 1
  15. #define SEC_PER_BLOCK 1
  16. #define BLKS_PER_TRACK 18
  17. #define CHARS_PER_BLOCK 512
  18. #define CHARS_PER_SEC CHARS_PER_BLOCK/SEC_PER_BLOCK
  19. #define SEC_MAP 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
  20. #define ID_STRING "cpio loader for PC-clone reading PC-clone disks"
  21.  
  22. /*   functions defined in this file */
  23.  
  24. void printblk( char *);
  25. void readblk(int blk, char *buf);  /* rewrite these three functions */
  26. void initdisk(void);              /* to adapt loader to your */
  27. void restore_disk(void);          /* operating system. */
  28.  
  29. int map_tab[ BLKS_PER_TRACK ] = { SEC_MAP };
  30.  
  31. main( argc, argv)
  32. int argc;
  33. char *argv[];
  34. {
  35. char buf[CHARS_PER_BLOCK + 1];
  36. char key_buf[MAX_LINE];
  37. int i, blk, num_blks ;
  38.  
  39. fprintf(stderr,"\n%s",ID_STRING);
  40. fprintf(stderr,"\nNumber of blocks to load ");
  41. num_blks = atoi(gets(key_buf));
  42.  
  43. /* clear buffer */
  44. for (i=0; i < CHARS_PER_BLOCK+1; i++, buf[i] = 0);
  45.  
  46. /* perform load */
  47. initdisk();
  48. for (blk = 0 ; blk < num_blks; blk += 1) {
  49.    readblk(blk,buf);
  50.    if (argc < 2)
  51.       fprintf(stderr,"\n\nBlock %d\n", blk);
  52.    printblk(buf);
  53.    }
  54. restore_disk();
  55. }
  56.  
  57. void printblk(buf)
  58. char * buf;
  59. {
  60. int i, k;
  61.  
  62. #if TESTING
  63. for (i=0, k=0; i < CHARS_PER_BLOCK; i++, k++){
  64.    if (isprint(buf[i])) putchar(buf[i]);
  65.    else putchar('.');
  66.    if (k == (DISP_WID - 1)) {
  67.       putchar('\n');
  68.       k = -1;
  69.       }
  70.    }
  71. putchar('\n');
  72.  
  73. #else
  74. for (i=0; i < CHARS_PER_BLOCK; i++) putchar(buf[i]);
  75.  
  76. #endif
  77. }
  78.  
  79. void readblk(blk_num,buf)
  80. int blk_num;
  81. char * buf;
  82.  
  83. {
  84. union REGS inreg, outreg;
  85. int block_offset, track_offset, mapped_blk;
  86.  
  87. block_offset = blk_num % BLKS_PER_TRACK;
  88. track_offset = blk_num / BLKS_PER_TRACK;
  89. mapped_blk = map_tab[block_offset] + track_offset * BLKS_PER_TRACK;
  90. #if TESTING
  91. fprintf(stderr,"\nmapped block = %d  ",mapped_blk);
  92. #endif
  93.  
  94. inreg.h.al = (char) (DR_SEL - 1);
  95. inreg.x.cx = 1;
  96. inreg.x.dx = mapped_blk;
  97. inreg.x.bx = (int) buf;
  98. int86(0x25, &inreg, &outreg);
  99. }
  100.  
  101. void initdisk()
  102. {
  103. char key_buf[MAX_LINE];
  104.  
  105. fprintf(stderr,"\nWhen drive light goes out, replace program disk");
  106. fprintf(stderr,"\nwith cpio disk. Press <return> to continue.");
  107. gets(key_buf);
  108. }
  109.  
  110. void restore_disk()
  111. {
  112. char key_buf[MAX_LINE];
  113.  
  114. fprintf(stderr,"\nWhen drive light goes out, replace cpio disk");
  115. fprintf(stderr,"\nwith a proper MS-DOS disk. Press <return> to continue.");
  116. gets(key_buf);
  117. }